﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace Bing.Toolkit.Utility
{
    public class MailHelper
    {
        private string _host;
        private string _from;
        private string _password;

        //public MailHelper()
        //{
        //    _host = ConfigureManager.Mail.Host;
        //    _from = ConfigureManager.Mail.From;
        //    _password = ConfigureManager.Mail.Password;
        //}

        public MailHelper(string host, string from, string password)
        {
            _host = host;
            _from = from;
            _password = password;
        }

        public void Send(string toAddress, string subject, string body)
        {
            Send(toAddress, subject, body, null, null);
        }

        public void Send(string toAddress, string subject, string body, List<string> ccAddress, List<string> bccAddress)
        {
            MailMessage mail = new MailMessage(_from, toAddress, subject, body);

            if (ccAddress != null && ccAddress.Count > 0)
            {
                ccAddress.ForEach(o => mail.CC.Add(o));
            }

            if (bccAddress != null && bccAddress.Count > 0)
            {
                bccAddress.ForEach(o => mail.Bcc.Add(o));
            }

            SmtpClient client = new SmtpClient();

            client.Host = _host;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Credentials = new System.Net.NetworkCredential(_from, _password);
            client.Send(mail);
        }
    }
}
